package com.itheima.web;

import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Reference
    private UserService userService;


    @PostMapping("/updatePW")
    public Result updatePW(@RequestBody User user){
        return  new Result(userService.updatePW(user));
    }





    @PostMapping("/findUsers")
    public Result findUsers(@RequestBody QueryPageBean queryPageBean){
        return new Result(userService.findUsers(queryPageBean));
    }



    @GetMapping("/findAll")
    @ApiOperation("查找所有用户")
    public Result findAll(){
        return new Result(userService.findAll());
    }


    @GetMapping("/delete/{id}")
    @ApiOperation("删除用户")
    public Result delete(@PathVariable("id") String id){
        return new Result(userService.delete(id));
    }

    @PostMapping("/save")
    @ApiOperation("添加用户")
    public Result save(@RequestBody User user){
        return new Result(userService.saveOrUpdate(user));
    }

}
